from typing import List, Callable


class Quest:
    def __init__(self, quest_id: [str, int], next_quest_id: [str, int] = None, enter_callable: Callable = None,
                 update_callable: Callable = None,
                 complete_condition_callable: Callable[..., bool] = None):
        self.next_quest_id = next_quest_id
        self.quest_id = quest_id
        self.enter_callable = enter_callable()
        self.update_callable = update_callable
        self.complete_condition_callable = complete_condition_callable
        self.is_complete = False

    def Run(self):
        if self.enter_callable: self.enter_callable()

    def Update(self):
        if self.complete_condition_callable():
            self.Complete()
        if self.update_callable:
            self.update_callable(self)

    def Complete(self):
        self.is_complete = True


class QuestList:
    def __init__(self, quest_list: List[Quest], start_quest_id=0, complete=None):
        self.current_quest_id = start_quest_id
        self.quest_list = quest_list
        self.current_quest: Quest = self.quest_list[self.current_quest_id]
        self.complete = complete

    def GetQuest(self, quest_id):
        for quest in self.quest_list:
            if quest.quest_id == quest_id:
                return quest

    def Run(self, quest_id):
        self.current_quest_id = quest_id
        self.current_quest = self.GetQuest(quest_id)
        if self.current_quest:
            self.current_quest.Run()

    def Update(self):
        self.current_quest.Update()
        if self.current_quest.is_complete:
            self.Next()

    def Next(self):
        if self.current_quest.next_quest_id:
            self.Run(self.current_quest.next_quest_id)
        else:
            if self.complete:
                self.complete()


i = 1
if __name__ == "__main__":

    def init_callable():
        global i
        i = 2


    def update_callable(quest):
        if quest.is_complete:
            print("complete")
        print(i)


    q1 = Quest(1, 2, init_callable, update_callable, lambda: i >= 2)
    q2 = Quest(2, None, init_callable, update_callable, lambda: i >= 4)
    quest_list = QuestList([q1, q2])

    cmd = input("q:")
    if cmd == "1":
        i += 1
        quest_list.Update()
